package controll;

import java.awt.List;
import java.io.IOException;

import org.nutz.dao.Cnd;
import org.nutz.dao.Dao;
import org.nutz.dao.impl.NutDao;

import com.alibaba.druid.sql.ast.expr.SQLCaseExpr.Item;
import com.guava.framework.Controller;
import com.mysql.jdbc.BlobFromLocator;

import pojo.nutz.Blogpage;

/**
 * IndexController
 */
public class BlogController extends Controller {
	public void add_form() throws IOException {
		render("blog_add_form.html");
	}

//	public void zbsz_add() throws IOException {
//		render("zhengbeishouzhang_add.html");
//	}

	public void test() {
		System.out.println("guava");
	}

	public void add() throws IOException {
		String title = getPara("title");
		int cat = getParaToInt("Fruit");
		String content1 = getPara("content");
		Blogpage bp = new Blogpage();
		bp.title = title;
		bp.cat = cat;
		bp.content1 = content1;
		bp.userid=Integer.parseInt(getSessionAttr("userid").toString());
		getDao().insert(bp);
		if (bp.id > 0) {
			System.out.println(bp.id);
			renderText("添加成功");
		} else {
			renderText("no");
		}
	}

	public void list() throws IOException {
		int id = Integer.parseInt(getSessionAttr("userid").toString());
		java.util.List blogpages = getDao().query(Blogpage.class, Cnd.where("userid", "=", id));
		String nsnns=null;
		 for(int i = 0; i < blogpages.size(); i++)  
	        {  
	            Blogpage b=(Blogpage) blogpages.get(i);
	            nsnns=nsnns+b.title+"<br>";
	        }  
		 renderText(nsnns);
	}
	public void get() throws IOException {
		int id = getParaToInt("id");
		Blogpage blogpage = getDao().fetch(Blogpage.class, id);
		if (blogpage != null) {
			setAttr("PG", blogpage);
			render("page_show.html");
		}

	}

	public void aiche() throws IOException {
		render("aiche.html");

	}

}
